<?require_once("connection.php");

$requestObject = json_decode($_REQUEST['data'], true);

$method = $requestObject["method"];

if($method=="deleteCourseStaff")
{
	$courseId = $requestObject["courseId"];
	$staffId = $requestObject["staffId"];
	deleteCourseStaff($courseId,$staffId,  $connection);
}
elseif($method=="addCourseStaff")
{
	$courseId = $requestObject["courseId"];
	$staffId = $requestObject["staffId"];
	addCourseStaff($courseId,$staffId,$connection);
}


function deleteCourseStaff($courseId,$staffId,$connection)
{
	require_once("connection.php");
	$Query = "DELETE FROM g_staff_course
	WHERE course_id=".$courseId." and staff_id=".$staffId;
	$result = mysql_query($Query, $connection);
	if(empty($result)){
		//echo "<pre>Failed to delete data</pre>";
		$message = "<pre>Failed to delete data</pre>";
	}
	else{
		//echo "<pre>data deleted</pre>";
		$message = "<pre>data deleted</pre>";
	}
	//JSON response
	//require_once("display_courses.php");
	header('Content-type: text/json');
	header('Content-type: application/json');
	$response = json_encode(array('id' => $staffId,
									'message' => $message));
	$response = json_encode($response);
	die($response);

}

function addCourseStaff($courseId,$staffId,$connection)
{
	$Query = "INSERT INTO g_staff_course(course_id, staff_id) VALUES(".$courseId.",".$staffId.");";
	$result = mysql_query($Query, $connection);
	if(empty($result)){
		//echo "<pre>Failed to delete data</pre>";
		$message = "<pre>Failed to delete data</pre>";
	}
	else{
		//echo "<pre>data deleted</pre>";
		$message = "<pre>data deleted</pre>";
	}
	//JSON response
	//require_once("display_courses.php");
	header('Content-type: text/json');
	header('Content-type: application/json');
	$response = json_encode(array('id' => $staffId,
									'message' => $message));
	$response = json_encode($response);
	die($response);
}

?>